package com.study.sort;

/**
 * - *@ClassName SelectSort
 * - *@Author LiuHuaBing
 * - *@Date 2021/12/7 10:31
 * - *@Version 1.0
 *
 * - 每一轮中找最小数字的过程不发生交换 找到这一轮中最小的数后最后 又顺序位子和最小数字索引位子数字交换
 */
public class SelectSort {

    public static void main(String[] args) {
        int arr[] = {9, 5, 4, 8, 6, 2, -5, 93,};
        arr = selectSort(arr);
        for (int i : arr) {
            System.out.println(i);
        }
    }


    private static int[] selectSort(int[] arr) {
        int temp;
        for (int i = 0; i < arr.length - 1; i++) {
            int min = arr[i];
            int index = i;
            for (int j = i; j < arr.length - 1; j++) {
                if (min > arr[j + 1]) {
                    min = arr[j + 1];
                    index = j + 1;
                }
            }
            temp = arr[i];
            arr[i] = min;
            arr[index] = temp;
        }
        return arr;
    }
}
